//
// Created by Jisam on 2024/8/6 15:29.
// solve tample
#include <bits/stdc++.h>

using namespace std;


void solve() {
    string s;
    cin >> s;
    int n = s.length();
    int f = 1;
    int ok = 0;
    if (n < 3) f = 0;
    for(int i = 0 ; i < n ; i ++){
        if(s[i]!= 'P'&&s[i]!='A'&&s[i]!='T'){
            f = 0;
        }
    }
    for(int i = 4 ; i < n ; i ++){
        if((s[i-4] == ' ' || s[i-4] =='A') && (s[i] == ' ' || s[i] =='A')
           &&s[i - 3] = 'P' && s[i - 2] = 'A' && s[i - 1] == 'T'){
            ok = 1;
        }
    }
    if(ok) {
        cout << "YES\n";
        return;
    }

    if(f == 0) {
        cout << "NO\n";
        return;
    }
    else cout << "YES\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}